package com.itheima.mapper;


import com.itheima.DTO.SubmitOrder;
import com.itheima.pojo.OderAndMember;
import com.itheima.pojo.Order;
import com.itheima.pojo.OrderSetting;
import io.swagger.v3.oas.annotations.Operation;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.Map;

@Mapper
public interface OrderMapper {

    @Select("select t_order.orderDate as orderDate,t_order.orderType as orderType," +
            "t_setmeal.code as setmeal,t_member.name as member " +
            " from t_order left join t_setmeal on t_setmeal.id = t_order.setmeal_id " +
            " left join t_member on t_member.id = t_order.member_id " +
            " where t_order.id = #{id}")
    OderAndMember findOrderAndMemberById(Integer id);


    @Select("select id from t_member where idCard = #{idCard}")
    Integer getMember(String idCard);


//    @Insert("insert into t_member(name,sex,idCard,phoneNumber,regTime) values" +
//            "(#{name},#{sex},#{idCard},#{telephone},#{date})")
//    @Options(useGeneratedKeys = true, keyProperty = "id")
    Integer addMember(Map<String, Object> params);



    @Select("select * from t_ordersetting where orderDate = #{date} ORDER BY id DESC LIMIT 1")
    OrderSetting findOrderSettingByDate(String date);


    @Select("select * from t_order where member_id = #{memberId} and orderDate = #{date} and setmeal_id = #{setmealId}")
    Order findOrderByMemberIdAndDate(Integer memberId, String date, Integer setmealId);


//    @Insert("insert into t_order(member_id,orderDate,orderType,orderStatus,setmeal_id) values" +
//            "(#{memberId},#{orderDate},#{orderType},#{orderStatus},#{setmealId})")
    Integer addOrder(Order order);
}
